#pragma once
//============================================================================
// Copyright (C) 2003-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

//NOTES: Strength, dex and intel should always sum to 65
//Sum of skills should = 100
#pragma pack(push) 
#pragma pack(1)

// check avatar name errors
//#define PKT_AVATAR_CHECK_NAME_ERR_EXISTS				1
//#define PKT_AVATAR_CHECK_NAME_ERR_INVALID_SYMBOL		2
//#define PKT_AVATAR_CHECK_NAME_ERR_TOO_SHORT				3
//#define PKT_AVATAR_CHECK_NAME_ERR_OFFENSIVE				4

#define PKT_AVATAR_CREATE_ERR_INVALID_PARAM				10
#define PKT_AVATAR_CREATE_ERR_MAX_ACCTS					11
#define PKT_AVATAR_CREATE_ERR_SRV_BUSY					12

#ifndef E_LOCATION_ID
#define ELocationId int
#endif

class AvatarModelInfo
{
public:
	// 41 bytes
	U8			u8Race;				//race .. if bit 7 set then female
	U8			u8HairStyle;		// hair style
	U8			u8FaceHairStyle;	// face hair style
	U16			u16HairColor;		// hair color
	U16			u16FaceHairColor;	// face hair color
	U16			u16SkinColor;		// skin color
	U16			u16ShirtColor;		// shirt color
	U16			u16PantsColor;		// pants color
	U32			u32ModelId;			// model id
	char		atcName[ PKT_MAX_AVATAR_NAME_LEN + 1 ];	// char name 
};
class AvatarHealth
{
public:
	// 3 bytes
	U8		u8Strength;		// strength / health
	U8		u8Dex;			// dexterity / stamina
	U8		u8Intel;		// intelligence / mana
};
class AvatarCreateInfo
{
public:
	// 10 bytes
	ELocationId		eLocationId;	//starting location from list of beginning locations
	U8				u8Skill1Type;	// first skill type
	U8				u8Skill1Value;	// first skill level
	U8				u8Skill2Type;	// second skill type
	U8				u8Skill2Value;	// second skill level
	U8				u8Skill3Type;	// third skill type
	U8				u8Skill3Value;	// third skill level
};

//============================================================================
class PktAvatarCreateReq : public VxPktHdr, public AvatarModelInfo, public AvatarHealth, public AvatarCreateInfo
{
public:
	PktAvatarCreateReq()
	{
		memset( this, 0, sizeof( PktAvatarCreateReq ) );
		m_u16PktLen = sizeof( PktAvatarCreateReq );
		m_u16PktType = PKT_TYPE_AVATAR_CREATE_REQ;
		vx_assert( 0 == ( m_u16PktLen & 0x0f ) );
	}
	_inline AvatarModelInfo *	GetAvatarModelInfo( void )	{ return (AvatarModelInfo *)this; }
	_inline AvatarHealth *		GetAvatarHealth( void )		{ return (AvatarHealth *)this; }
	_inline AvatarCreateInfo *	GetAvatarCreateInfo( void )	{ return (AvatarCreateInfo *)this; }

	BOOL	VerifyPkt( void ); // verify packet params

	//=== vars ===//
	U32		u32Res;		// reserved for alignment
};

//============================================================================
inline BOOL	PktAvatarCreateReq::VerifyPkt( void ) // verify packet params
{
	int i;
	i = (int)strlen( atcName );
	if( i == 0 || i > PKT_MAX_AVATAR_NAME_LEN )
	{
		// invalid name length
		return FALSE;
	}
	return TRUE;
}

//============================================================================
class PktAvatarCreateReply : public VxPktHdr
{
public:
	PktAvatarCreateReply()
	{
		memset( this, 0, sizeof( PktAvatarCreateReply ) );
		m_u16PktLen = sizeof( PktAvatarCreateReply );
		m_u16PktType = PKT_TYPE_AVATAR_CREATE_REPLY;
		vx_assert( 0 == (m_u16PktLen & 0x0f ));
	}
	U8		u8Idx;			// index of created character
	U8		u8Res;			// reserved for alignment
	U32		u64Sn;			// serial number of avatar
	U32		u32Error;		// error code if any
};
#pragma pack(pop)
